package com.maochang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maochang.pojo.PsInspectiontaskDetail;
import com.maochang.pojo.PsSystemconfig;
import com.maochang.pojo.util.Result;
import com.maochang.pojo.util.Result1;
import com.maochang.service.PsSystemConfigService;
import com.maochang.service.QueXianDengJiQuRenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 缺陷管理
 */
@Slf4j
@RestController
@RequestMapping("/QuXianGuAnLi")
public class QuXianGuAnLi {

    @Resource
    private PsSystemConfigService psSystemConfigServiceImpl;

    @Resource
    private QueXianDengJiQuRenService queXianDengJiQuRenImpl;
    /**
     * 主菜单  点击 缺陷等级设置跳转
     * @return
     * @throws IOException
     */
    @GetMapping("/qxLeiXiNgSheZhi")
    public ModelAndView index2() throws IOException {
        return  new ModelAndView("quxianguanli/DefectTypeSetting") ;
    }

    /**
     * 数据加载
     * @return
     */
    @GetMapping("/qxTypeSheZhiJson")
    public Result ChQuXianLeiXIng(){
      Result result=  Result.success(psSystemConfigServiceImpl.ChaPsSystemConfig());
      return  result;
    }

    /**
     * 缺陷名称更改
     * @param psSystemconfig
     * @return
     */
    @PostMapping("/qxTypeUpdate")
    public  Result qxTypeUpdate(PsSystemconfig psSystemconfig){
        Result result =new Result();
        boolean fAlg=psSystemConfigServiceImpl.QuGeNgGai(psSystemconfig);
        if(fAlg==true){
            result.setMsg("信息更新成功");
        }
        return result;
    }
    /**
     * 缺陷状态更改
     * @param id
     * @param zhuAngTai
     * @return
     */
    @PostMapping("/qxZhuAngTaiGai")
    public  Result qxZhuAngTaiGai(Integer id,Integer zhuAngTai){
        Result result =new Result();
        boolean fAlg=psSystemConfigServiceImpl.QxZhuAngTai(id,zhuAngTai);
        if(fAlg==true){
            result.setMsg("状态更新成功");
        }
        return result;
    }

    /**
     * 缺陷类型增加
     * @param configCode
     * @param configName
     * @param isStart
     * @return
     */
    @PostMapping("/quXianAdd")
    public  Result addQxMessage(String configCode,String configName, String isStart){
        Result result =new Result();
        PsSystemconfig psSystemconfig=new PsSystemconfig();
        psSystemconfig.setConfigCode(configCode);
        psSystemconfig.setConfigName(configName);
        Integer zhuangTai=0;
        if(isStart.equals("on")){
            zhuangTai=1;
        }
        psSystemconfig.setIsStart(zhuangTai);
        boolean fAlg=psSystemConfigServiceImpl.addQxXin(psSystemconfig);
        if(fAlg){
            result.setMsg("成功");
            return result;
        }else {
            result.setMsg("失败");
            return result;
        }
    }

    /**
     * 缺陷类型删除
     * @param id
     * @return
     */
    @PostMapping("/quxShanCHu")
    public  Result ShanCHu(String id){
        Result result =new Result();
        boolean fAlg=psSystemConfigServiceImpl.ShanCHu(id);
        if(fAlg){
            result.setMsg("成功");
            return result;
        }else {
            result.setMsg("失败");
            return result;
        }
    };

    /**
     * 等级确认 页面跳转
     * @return
     */
    @GetMapping("/QuXianDengJi")
    public  ModelAndView QuXianDengJi(){
        return  new ModelAndView("quxianguanli/DefectLevelConfirmation");
    };

    /**
     * 缺陷等级确认 查询
     * @return
     */
    @GetMapping("/quXianDengJiQuRen")
    public Result1 QuXianDengJson(PsInspectiontaskDetail psInspectiontaskDetail, String kaishi, String jeiShu,@RequestParam("page") int current, @RequestParam("limit") int size,HttpSession session){
        Page<PsInspectiontaskDetail> psInspectiontaskDetails= queXianDengJiQuRenImpl.CHaXunZiRenWu(psInspectiontaskDetail,current,size,kaishi,jeiShu,session);
        return   Result1.success1(psInspectiontaskDetails);
    }
    /**
     * 缺陷等级确认保存
     * @return
     */
    @PostMapping("/QuXianDengJiBaoCun")
    public Result QuXianDengJiBaoCun(String id,String qxJb){
        Result re=new Result();
        System.out.println(qxJb+"aaaa");
        Boolean aa= queXianDengJiQuRenImpl.gaiZhuangTai(id,qxJb);
        System.out.println(aa+"是否成功");
        if(aa){
            re.setMsg("确认等级成功");
            return re;
        }
        re.setMsg("确认等级失败");
        return re;
    }
}
